﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace Game3D
{
    [Serializable]
    internal class GameShapes 
    {
        /// <summary>
        /// Triangles of Single
        /// </summary>
        public static Int32Collection Single = new Int32Collection() 
            { 
                // FRONT
                00, 01, 05,
                05, 04, 00,

                // RIGHT
                01, 21, 25,
                25, 05, 01,

                // BACK
                20, 24, 25,
                25, 21, 20,

                // LEFT
                04, 24, 20,
                04, 20, 00,

                // TOP
                04, 05, 25,
                25, 24, 04,

                // BOTTOM
                00, 20, 21,
                21, 01, 00
            };

        /// <summary>
        /// Triangles of O
        /// </summary>
        public static Int32Collection O = new Int32Collection() 
            { 
                // FRONT
                00, 02, 10,
                10, 08, 00,

                // RIGHT
                02, 22, 30,
                30, 10, 02,

                // BACK
                20, 28, 30,
                30, 22, 20,

                // LEFT
                08, 28, 20,
                08, 20, 00,

                // TOP
                08, 10, 30,
                30, 28, 08,

                // BOTTOM
                00, 20, 22,
                22, 02, 00
            };

        /// <summary>
        /// Triangles of I
        /// </summary>
        public static Int32Collection I = new Int32Collection() 
            { 
                // FRONT
                00, 01, 17,
                17, 16, 00,

                // RIGHT
                01, 21, 37,
                37, 17, 01,

                // BACK
                21, 20, 36,
                36, 37, 21,

                // LEFT
                16, 36, 20,
                16, 20, 00,

                // TOP
                16, 17, 37,
                37, 36, 16,

                // BOTTOM
                00, 20, 21,
                21, 01, 00
            };

        /// <summary>
        /// Triangles of L
        /// </summary>
        public static Int32Collection L = new Int32Collection() 
            { 
                // === BASE SHAPE ===
                // FRONT
                00, 01, 13,
                13, 12, 00,

                // RIGHT
                05, 25, 33,
                33, 13, 05,

                // BACK
                21, 20, 32,
                32, 33, 21,

                // LEFT
                12, 32, 20,
                12, 20, 00,

                // TOP
                12, 13, 33,
                33, 32, 12,

                // BOTTOM
                00, 20, 21,
                21, 01, 00,

                // === ADDITIONAL BLOCK ON THE BOTTOM RIGHT ===
                // FRONT
                05, 01, 02,
                02, 06, 05,

                // RIGHT
                02, 22, 26,
                26, 06, 02,

                // BACK
                21, 25, 26,
                26, 22, 21,

                // TOP
                05, 06, 26,
                26, 25, 05,

                // BOTTOM
                01, 21, 22,
                22, 02, 01
            };
        public static Int32Collection S = new Int32Collection
         {
             // === BASE SHAPE ===
                // FRONT
                00, 02, 06,
                06, 04, 00,

                // RIGHT
                02, 22, 26,
                26, 06, 02,

                // BACK
                26, 22, 20,
                20, 24, 26,

                // LEFT
                24, 20, 00,
                00, 04, 24,

                // TOP
                04, 05, 25,
                25, 24, 4,

                // BOTTOM
                22, 02, 00,
                00, 20, 22,

                // === ADDITIONAL BLOCK ON THE TOP ===
                // FRONT
                05, 07, 11,
                11, 09, 05,

                // RIGHT
                07, 27, 31,
                31, 11, 07,

                // BACK
                31, 27, 25,
                25, 29, 31,

                // LEFT
                29, 25, 05,
                05, 09, 29,

                // TOP
                09, 11, 31,
                31, 29, 09,

                // BOTTOM
                27, 07, 05,
                05, 25, 27
           };
        public static Int32Collection Z = new Int32Collection
        {
            // === BASE SHAPE ===
                // FRONT
                05, 01, 03,
                03, 07, 05,

                // RIGHT
                03, 23, 27,
                27, 07, 03,

                // BACK
                27, 23, 21,
                21, 25, 27,

                // LEFT
                25, 21, 01,
                01, 05, 25,

                // TOP
                06, 07, 27,
                27, 26, 06,

                // BOTTOM
                23, 03, 01,
                01, 21, 23,

                // === ADDITIONAL BLOCK ON THE TOP ===
                // FRONT
                04, 06, 10,
                10, 08, 04,

                // RIGHT
                06, 26, 30,
                30, 10, 06,

                // BACK
                30, 26, 24,
                24, 28, 30,

                // LEFT
                28, 24, 04,
                04, 08, 28,

                // TOP
                08, 10, 30,
                30, 28, 08,

                // BOTTOM
                25, 05, 04,
                04, 24, 25
        };

        public static Int32Collection J = new Int32Collection
        {
            // === BASE SHAPE ===
                // FRONT
                01, 02, 14,
                14, 13, 01,

                // RIGHT
                02, 22, 34,
                34, 14, 02,

                // BACK
                34, 22, 21,
                21, 33, 34,

                // LEFT
                33, 25, 05,
                05, 13, 33,

                // TOP
                13, 14, 34,
                34, 33, 13,

                // BOTTOM
                22, 02, 01,
                01, 21, 22,

                // === ADDITIONAL BLOCK ON THE LEFT ===
                // FRONT
                04, 00, 01,
                01, 05, 04,

                // BACK
                25, 21, 20,
                20, 24, 25,

                // LEFT
                04, 24, 20,
                20, 00, 04,

                // TOP
                04, 05, 25,
                25, 24, 04,

                // BOTTOM
                21, 01, 00,
                00, 20, 21
        };

        public static Int32Collection T = new Int32Collection 
        {
            // === BASE SHAPE ===
                // FRONT
                04, 07, 11,
                11, 08, 04,

                // RIGHT
                07, 27, 31,
                31, 11, 07,

                // BACK
                24, 28, 31,
                31, 27, 24,

                // LEFT
                24, 04, 08,
                08, 28, 24,

                // TOP
                08, 11, 31,
                31, 28, 08,

                // BOTTOM
                24, 25, 05,
                05, 04, 24,

                26, 27, 07,
                07, 06, 26,

                // === ADDITIONAL BLOCK ON THE BOTTOM ===
                // FRONT
                01, 02, 06,
                06, 05, 01,

                // RIGHT
                02, 22, 26,
                26, 06, 02,

                // BACK
                21, 25, 26,
                26, 22, 21,

                // LEFT
                21, 01, 05,
                05, 25, 21,

                // BOTTOM
                21, 22, 02,
                02, 01, 21
        };


        public static Int32Collection ResolveShape(Shape shapeToResolve)
        {
            Int32Collection value;
            switch (shapeToResolve)
            {
                case Shape.J:
                    value = J;
                    break;
                case Shape.I:
                    value = I;
                    break;
                case Shape.L:
                    value = L;
                    break;
                case Shape.O:
                    value = O;
                    break;
                case Shape.Single:
                    value = Single;
                    break;
                case Shape.T:
                    value = T;
                    break;
                case Shape.Z:
                    value = Z;
                    break;
                case Shape.S:
                    value = S;
                    break;
                default:
                    value = Single;
                    break;
            }

            return value;
        }


        public static Shape ResolveShape(Int32Collection shapeToResolve)
        {
            Shape value = Shape.Single;

            if (shapeToResolve == I)
            {
                value = Shape.I;
            }
            else if (shapeToResolve == J)
            {
                value = Shape.J;
            }
            else if (shapeToResolve == L)
            {
                value = Shape.L;
            }
            else if (shapeToResolve == O)
            {
                value = Shape.O;
            }
            else if (shapeToResolve == Single)
            {
                value = Shape.Single;
            }
            else if (shapeToResolve == T)
            {
                value = Shape.T;
            }
            else if (shapeToResolve == Z)
            {
                value = Shape.Z;
            }
            else if (shapeToResolve == S)
            {
                value = Shape.S;
            }

            return value;
        }
    }
}
